namespace nu.Commands
{
    using System;
    using CommandLine;
    using Model;

    public class InjectCommand : Command
    {
        private readonly ILocalPackageRepository _localPackageRepository;
        private readonly IFileSystem _fileSystem;

        [Argument(ArgumentType.Required, HelpText = "The name of the product to inject.", LongName = "product", ShortName = "p")]
        public string Product;

        [Argument(ArgumentType.AtMostOnce, HelpText = "The version of the product to inject.", LongName = "version", ShortName = "v", DefaultValue = "Edge")]
        public string Version;

        public InjectCommand(ILocalPackageRepository localPackageRepository, IFileSystem fileSystem)
        {
            _localPackageRepository = localPackageRepository;
            _fileSystem = fileSystem;
        }


        public override void Execute()
        {
            if(string.IsNullOrEmpty(Product)) throw new ArgumentNullException("Product", "You must specify a product to inject");

            Console.WriteLine("Injecting {0} with version {1}", Product, Version ?? "edge");

            Package pkg = _localPackageRepository.Find(Product);
            //get dependencies

            //write it to disk someplace
            _fileSystem.Write(null);

            Console.WriteLine("Finished Injecting {0}", Product);
        }

        public override string Name
        {
            get { return "Inject"; }
        }
    }
}